package com.kb5173.search.index.utils;

import com.kb5173.search.common.entity.GoodsEO;
import com.kb5173.search.index.document.GoodsDocument;
import com.kb5173.framework.dataaccess.pagination.GenericPage;
import com.kb5173.framework.shared.utils.BeanMapper;
import org.springframework.data.domain.Page;

import java.util.List;

/**
 * @author Chengfei.Sun
 */
public class PageTransformUtil {
    /**
     * spring solr page类型转换为GenericPage
     *
     * @param page
     * @return
     */
    public static GenericPage<GoodsEO> covertPage(Page<GoodsDocument> page) {
        GenericPage<GoodsEO> genericPage = new GenericPage<GoodsEO>(
                page.getNumber() * page.getSize(), page.getTotalElements(),
                page.getSize(), null);
        if (page.hasContent()) {
            List<GoodsEO> list = BeanMapper.mapList(
                    page.getContent(), GoodsEO.class);
            genericPage.setData(list);
        }
        return genericPage;
    }
}
